﻿using System;
using System.Collections.Generic;
using System.Text;
using IRCServer.Entities.Commands;
using IRCServer.Utilities;
using IRCServer.Entities;

namespace IRCServer.CommandHandlers
{
    class SERVERCommandHandler : CommandHandlerBase
    {
        public override string HandleCommand(global::IRCServer.Entities.Commands.IRCCommandBase command, global::IRCServer.Entities.SessionBase session)
        {
            if (command is SERVERCommand)
            {
                SERVERCommand serverCommand = (SERVERCommand)command;

                if (serverCommand.HostName==null )
                {
                    return Errors.GetErrorResponse(ErrorCode.ERR_NEEDMOREPARAMS, string.Empty);
                }

                if (session is ServerSession)//server connecting for the first time.
                {
                    ServerSession serverSession = (ServerSession)session;
                    serverSession.ServerNodeID = serverCommand.NodeID;
                    serverCommand.HostName = serverCommand.HostName;
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            return string.Empty;
        }
    }
}
